<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>

    var today = new Date();//获得当前日期
    var years = today.getFullYear();//获得年份
    var month = today.getMonth() + 1;//此方法获得的月份是从0---11，所以要加1才是当前月份
    var year = [  //这里是自己自定义开始日期
        {
            a: 2015,
            b: [
                {m: 12}
            ]
        }
    ]
    var num = year[0].a;
    var d = years - year[0].a;
    console.log(d);
    if (d < 1) {
        year = year;
    } else {
        var g = [];
        for (var j = 1; j <= 12; j++) {
            var e = {m: j}
            g.push(e)
        }
        var h = [];
        for (var k = 1; k <= month; k++) {
            var e = {m: k}
            h.push(e)
        }
        for (var i = 1; i < d; i++) {
            var c = {
                a: ++num,
                b: g
            }
            year.push(c)
        }
        var m = {
            a: years,
            b: h
        }
        year.push(m);

        console.log("进不进来");
    }
    console.log(year);

    console.log(years);
    var rrr = [];

    for (var i = 0; i < year.length; i++) {
        rrr.push(year[i].a)
        for (var j = 0; j < year[i].b.length; j++) {
            rrr.push(year[i].b[j].m)
        }
    }
    console.log(rrr);

    //这里是为了 获取我点击的时候  知道点的是那一年的月份  ↓↓↓↓

    var index = 10;  //可以通过索引拿到当前月  这里的索引 到时候
                    // 我是点击的时候  拿到的动态索引 不会超出  所以这里没有加判断
    for (var i = index; i >= 0; i--) {
        if (rrr[i] > 12) {
            console.log(rrr[i]); //获取当前点击的年
            break;
        };
    }


</script>
</body>
</html>